/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var tabla;
var form;

function creaTabla()
{
    tabla = doc.createElement("table");
    tabla.setAttribute("id", "data");

    var thead = doc.createElement("thead");
    thead.setAttribute("id", "datah");

    var tbody = doc.createElement("tbody");
    tbody.setAttribute("id", "datab");

    var nombreEmpresa = document.createElement("th");
    nombreEmpresa.innerHTML = " Nombre Empresa ";
    var contacto = document.createElement("th");
    contacto.innerHTML = " Contacto ";
    var telefonoContacto = document.createElement("th");
    telefonoContacto.innerHTML = " Telefono Contacto ";
    var mailContacto = document.createElement("th");
    mailContacto.innerHTML = " Email Contacto ";
    var estadoSolicitud = document.createElement("th");
    estadoSolicitud.innerHTML = " Estado Solicitud ";
    var modalidad = document.createElement("th");
    modalidad.innerHTML = " Modalidad ";
    var fechaRegistro = document.createElement("th");
    fechaRegistro.innerHTML = " Fecha Registro ";
    var codigoSolicitud = document.createElement("th");
    codigoSolicitud.innerHTML = " Codigo Solicitud ";
    var descripcion = document.createElement("th");
    descripcion.innerHTML = " Descripcion ";
    thead.appendChild(nombreEmpresa);
    thead.appendChild(contacto);
    thead.appendChild(telefonoContacto);
    thead.appendChild(mailContacto);
    thead.appendChild(estadoSolicitud);
    thead.appendChild(modalidad);
    thead.appendChild(fechaRegistro);
    thead.appendChild(codigoSolicitud);
    thead.appendChild(descripcion);

    tabla.appendChild(thead);
    tabla.appendChild(tbody);
}
;

function cargaDatosTabla(nombrediv)
{
    doc.getElementById(nombrediv).appendChild(tabla);

    table = doc.getElementById("data");
    var tb = table.tBodies[0];
    for (; tb.childElementCount; )
        tb.removeChild(tb.children[0]);

    var myNames = ["Carlos Gomez", "Maria Perez", "Daniela Mena", "Juan Sandoval", "Karen Diaz", "Pamela Zuñiga", "Ernesto Loria", "Javier Oviedo", "Marta Rojas", "Luisa Murillo"];
    var myNumbers = ["22549895", "22547148", "78541248", "32151484", "89789080", "89102330", "45741524", "56412540", "22548741", "36250148"];
    var myMails = ["a@a.com", "b@b.com", "c@c.com", "d@d.com", "e@e.com", "f@f.com", "g@g.com", "h@h.com", "i@i.com", "j@j.com"];
    var estados = ["activa", "inactiva"];
    var mods = ["Ingenieria", "PPA", "Proyectos Graduacion"];
    var myDates = ["20-sept-2013", "10-jul-2013", "18-ene-2013", "15-feb-2013", "20-mar-2013", "05-ene-2013", "09-sept-2013", "25-nov-2013", "20-abr-2013", "26-ene-2013"];
    var myDesc = ["asrfgalubsdf", "wasgawf", "1asfbaswefb", "wrgqwergqw", "sfokiuhso", "awkjbvqkiw", "sdfkvjbsadfvk", "awdkjhbasd", "asdfkjvbswfk", "jawdkjhbwd"];
    var EmpresaNames = ["ICE", "AyA", "Escuela Quimica", "Ministerio de Educacion", "CCSS", "Escuela Benito Perez", "MAG", "HP", "ICE", "Registro UNA"];
    var i;
    var j = 22554;
    for (i = 0; i < 10; i++)
    {
        var tr = tb.insertRow(i);
        // tr.setAttribute("onclick", "verDetallesSolicitud");	
        var nombreEmpresa = tr.insertCell(0);
        var contacto = tr.insertCell(1);
        var telefonoContacto = tr.insertCell(2);
        var mailContacto = tr.insertCell(3);
        var estadoSolicitud = tr.insertCell(4);
        var modalidad = tr.insertCell(5);
        var fechaRegistro = tr.insertCell(6);
        var codigoSolicitud = tr.insertCell(7);
        var descripcion = tr.insertCell(8);

        if (nombrediv == "tableDiv") {
            nombreEmpresa.innerHTML = EmpresaNames[0];
        }
        else {
            nombreEmpresa.innerHTML = EmpresaNames[i];
        }
        contacto.innerHTML = myNames[i];
        telefonoContacto.innerHTML = myNumbers[i];
        mailContacto.innerHTML = myMails[i];
        estadoSolicitud.innerHTML = estados[Math.floor(Math.random() * estados.length)];
        modalidad.innerHTML = mods[Math.floor(Math.random() * mods.length)];
        fechaRegistro.innerHTML = myDates[i];
        codigoSolicitud.innerHTML = j;
        descripcion.innerHTML = myDesc[i];
        j++;
    }

    document.getElementById(nombrediv).appendChild(form);
}
;

function filter(term, _id, cellNr) {
    var suche = term.value.toLowerCase();
    var table = document.getElementById(_id);
    var ele;
    for (var r = 0; r < table.rows.length; r++) {
        ele = table.rows[r].cells[cellNr].innerHTML.replace(/<[^>]+>/g, "");
        if (ele.toLowerCase().indexOf(suche) >= 0)
            table.rows[r].style.display = '';
        else
            table.rows[r].style.display = 'none';
    }
}
;

function filter_aux1(term) {
    filter(term, 'data', 0);
}
;

function filter_aux2(term) {
    filter(term, 'data', 4);
}
;

function filter_aux3(term) {
    filter(term, 'data', 5);
}
;

/*
 function filter2 (phrase, _id){
 var words = phrase.value.toLowerCase().split(" ");
 var table = document.getElementById(_id);
 var ele;
 for (var r = 1; r < table.rows.length; r++){
 ele = table.rows[r].innerHTML.replace(/<[^>]+>/g,"");
 var displayStyle = 'none';
 for (var i = 0; i < words.length; i++) {
 if (ele.toLowerCase().indexOf(words[i])>=0)
 displayStyle = '';
 else {
 displayStyle = 'none';
 break;
 }
 }
 table.rows[r].style.display = displayStyle;
 }
 };
 */
function inputForms()
{
    form = document.createElement("form");
    form.setAttribute("id", "formEst");
    form.setAttribute("class", "formss");

    var fieldset = document.createElement("fieldset");
    fieldset.setAttribute("id", "fieldEst");
    fieldset.setAttribute("class", "fields");
    form.appendChild(fieldset);

    var label1 = document.createElement("label");
    label1.innerHTML = "Nombre ";
    fieldset.appendChild(label1);

    var input1 = document.createElement("input");
    input1.setAttribute("id", "inname");
    input1.setAttribute("onkeyup", "filter_aux1(this)");
    fieldset.appendChild(input1);

    var label2 = document.createElement("label");
    label2.innerHTML = "Modalidad ";
    fieldset.appendChild(label2);

    var input2 = document.createElement("input");
    input2.setAttribute("id", "inmod");
    input2.setAttribute("onkeyup", "filter_aux2(this)");
    fieldset.appendChild(input2);

    var label3 = document.createElement("label");
    label3.innerHTML = "Estado ";
    fieldset.appendChild(label3);

    var input3 = document.createElement("input");
    input3.setAttribute("id", "inestado");
    input3.setAttribute("onkeyup", "filter_aux3(this)");
    fieldset.appendChild(input3);

    //document.getElementById(nombrediv).appendChild(form);
}
;

